<template>
  <div class="main_spac1 maincl">
    <div class="main_white padding10">
      <div class="mainor_form">
        <div class="mainor_te">
          <el-button @click="addAction" class="marginLeft10" type="primary">新增</el-button>
        </div>
        <el-form :inline="true" :model="form" class="demo-form-inline" ref="userListFrom" label-width="80px">
          <el-form-item label="模板名称" prop="company_name">
            <el-input clearable v-model.trim="form.company_name" placeholder="模板名称" class="wid220"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button class="reset marginLeft10" type="primary" @click="reset()">重置</el-button>
            <el-button type="primary" @click="getArticleList" :loading="listLoading">搜索</el-button>
          </el-form-item>
        </el-form>
      </div>

      <div class="main_table" style="min-height: 590px">
        <el-table ref="multipleTable" v-loading="listLoading" :data="list" element-loading-text="加载中" fit border
          highlight-current-row @selection-change="handleSelectionChange">
          <el-table-column type="index" />
          <el-table-column label="模板名称" width="130" show-overflow-tooltip>
            <template slot-scope="scope">{{ scope.row.formwork }}</template>
          </el-table-column>
          <el-table-column label="模板内容" show-overflow-tooltip>
            <template slot-scope="scope">{{ scope.row.formwork_content }}</template>
          </el-table-column>
          <el-table-column width="260">
            <template slot="header">
              <span>模板状态:
                <el-tooltip class="item" effect="dark" content="切换成功后会设置为默认模板" placement="top">
                  <i class="el-icon-info" title=""></i>
                </el-tooltip>
              </span>
            </template>
            <template slot-scope="scope">
              <el-switch v-model="scope.row.state" active-color="#13ce66" inactive-color="#ff4949" active-text="设为默认"
                inactive-text="取消默认" :active-value="1" :inactive-value="0">
              </el-switch>
            </template>
          </el-table-column>
          <el-table-column fixed="right" label="操作" width="180">
            <template slot-scope="scope">
              <el-button @click="addAction(scope.row.id)" type="text" size="mini" class="handle_btn">修改</el-button>
              <el-button @click="examine(scope.row)" type="text" size="mini" class="handle_btn">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>

      <div class="main_page boxdq">
        <div></div>
        <div class="main_page_r">
          <el-pagination :current-page="current.page" :page-sizes="[5, 30, 50, 100]" :page-size="current.limit"
            layout="total, sizes, prev, pager, next, jumper" :total="totalCount" background @size-change="changeLimit"
            @current-change="changePage" />
        </div>
      </div>
    </div>

    <el-dialog :title="formworkTitle" :visible.sync="releaseVisible" width="70%" :close-on-click-modal="false">
      <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
        <el-form-item label="模板名称:" prop="name">
          <el-input v-model="ruleForm.name" clearable placeholder="请输入模板名称"></el-input>
        </el-form-item>
        <el-form-item label="模板内容:" prop="content">
          <el-input v-model="ruleForm.content" type="textarea" placeholder="请输入模板内容" :rows="2"></el-input>
        </el-form-item>
        <el-form-item label="是否设置默认:" prop="state">
          <el-switch v-model="ruleForm.state" active-color="#13ce66" inactive-color="#ff4949" active-text="设为默认"
            inactive-text="取消默认" :active-value="1" :inactive-value="0">
          </el-switch>
        </el-form-item>
      </el-form>

      <span slot="footer" class="dialog-footer">
        <el-button @click="releaseVisible = false">取 消</el-button>
        <el-button type="primary" @click="releaseVisible = false">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { uploadPath } from "@/api/currency";
import { apiUrl, objKeySort, Md5 } from "@/utils/public";
import { Debounce } from '@/utils/index'
export default {
  name: 'residues',
  data() {
    return {
      // 搜索条件
      form: {
        // 模板名称
        company_name: null,
      },
      // 加载功能
      listLoading: false,
      // 列表字段
      list: [{
        formwork: '模板1',
        formwork_content: '中控系统发生预警,系统检测商品超标且呈上升趋势,检测值:XX,时间:XX,请及时处理,谢谢',
        state: 1,
      }, {
        formwork: '模板2',
        formwork_content: '温馨提示:系统设置的商品检测数据高于正常值,为了食品安全,请及时处理,时间:xx,谢谢',
        state: 0,
      }],

      // 模板模态框
      releaseVisible: false,
      // 模板模态框标题
      formworkTitle: null,

      uploadPath,
      ruleForm: {
        name: null,
        content: null,
        state: 0
      },
      rules: {
        name: [{ required: true, message: '请输入模板名称', trigger: 'blur' }],
        content: [{ required: true, message: '请输入模板名称', trigger: 'blur' }],
      },

      // 分页
      current: {
        page: 1,
        limit: 5,
      },
      totalCount: 0,
    }
  },
  mounted() {
  },
  methods: {
    // 切换分页大小
    changeLimit(e) {
      this.current.limit = e
      this.getSupplierList()
    },
    // 切换分页
    changePage(e) {
      this.current.page = e
      this.getSupplierList()
    },
    // 新增/修改模板
    addAction(id) {
      this.releaseVisible = true
      if (!id) {
        this.formworkTitle = '修改模板'
      } else {
        this.formworkTitle = '新增模板'
      }
    },
    // 重置
    reset() {

    },
    // 搜索
    getArticleList() {

    },
    // 删除模板
    examine(row) {
      this.$confirm('此操作将永久删除该模板, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$message({
          type: 'success',
          message: '删除成功!'
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },

    // 打开链接预览图片
    openLink(link) {
      this.linkUrl = null
      this.linkUrl = link
      this.linkVisible = true
    }
  }
}
</script>

<style lang="scss" scoped>
.maincl {


  .handle_btn {
    padding: 0;
    border: 0;
  }


  .mainor_form form {
    width: 100%;
  }

  .main_table /deep/.el-table--small td {
    padding: 10px 0;
  }

  .main_table /deep/.el-table--small th {
    padding: 10px 0;
  }

  /deep/.el-table {
    tr {
      &:hover {
        background: none !important;
      }

      &.hover-row>td {
        background: none !important;
      }

      .current-row>td {
        background: none !important;
      }
    }
  }

  /deep/.main_table .el-table--small td .cell {
    height: auto !important;
  }

  /deep/.el-table .el-table__body tr:hover {
    background: #fff !important;
  }

  /deep/.el-table .el-table__body tr:hover>td {
    background: #fff !important;
  }

  /deep/.el-table tr.expanded+tr {
    background: #fafafa !important;
  }

  /deep/.el-table tr.expanded+tr>td {
    background: #fafafa !important;
  }

  /deep/.el-table tr.expanded+tr .mainex_ta {
    background: #fafafa !important;
  }

  /deep/.el-table tr.expanded+tr .mainex_ta th,
  /deep/.el-table tr.expanded+tr .mainex_ta tr {
    background: #fafafa !important;
  }

  /deep/.el-table tr.expanded+tr:hover {
    background: #fafafa !important;
  }

  /deep/.el-table tr.expanded+tr:hover>td {
    background: #fafafa !important;
  }

  /deep/.el-table tr.expanded+tr .el-table tr:hover {
    background: #fafafa !important;
  }

  /deep/.el-table tr.expanded+tr .el-table tr:hover>td {
    background: #fafafa !important;
  }

  /deep/.el-table .cell {
    display: flex;
    align-items: center;
  }

  /deep/.boxdq {
    justify-content: flex-end;
  }
}

.exptitle {
  padding: 10px 0px;
}

.linkSpan {
  text-decoration: underline;
  color: rgb(0, 255, 21);
  cursor: pointer;
}

.showSpan {
  width: 400px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 5; //控制显示几行
  -webkit-box-orient: vertical; //webbox方向
  white-space: wrap;
}
</style>